package com.ruoyi.zsyh.controller;

import java.util.List;

import com.ruoyi.zsyh.domain.ZsyhUserPartsstore;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.zsyh.service.IZsyhUserPartsstoreService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 配件店档案Controller
 * 
 * @author yuexl
 * @date 2021-12-21
 */
@Controller
@RequestMapping("/zsyh/partsStore")
public class ZsyhUserPartsstoreController extends BaseController
{
    private String prefix = "zsyh/partsStore";

    @Autowired
    private IZsyhUserPartsstoreService zsyhUserPartsstoreService;

    @RequiresPermissions("zsyh:partsStore:view")
    @GetMapping()
    public String partsStore()
    {
        return prefix + "/repairStore";
    }

    /**
     * 查询配件店档案列表
     */
    @RequiresPermissions("zsyh:partsStore:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ZsyhUserPartsstore zsyhUserPartsstore)
    {
        startPage();
        List<ZsyhUserPartsstore> list = zsyhUserPartsstoreService.selectZsyhUserPartsstoreList(zsyhUserPartsstore);
        return getDataTable(list);
    }

    /**
     * 导出配件店档案列表
     */
    @RequiresPermissions("zsyh:partsStore:export")
    @Log(title = "配件店档案", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ZsyhUserPartsstore zsyhUserPartsstore)
    {
        List<ZsyhUserPartsstore> list = zsyhUserPartsstoreService.selectZsyhUserPartsstoreList(zsyhUserPartsstore);
        ExcelUtil<ZsyhUserPartsstore> util = new ExcelUtil<ZsyhUserPartsstore>(ZsyhUserPartsstore.class);
        return util.exportExcel(list, "配件店档案数据");
    }

    /**
     * 新增配件店档案
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存配件店档案
     */
    @RequiresPermissions("zsyh:partsStore:add")
    @Log(title = "配件店档案", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ZsyhUserPartsstore zsyhUserPartsstore)
    {
        return toAjax(zsyhUserPartsstoreService.insertZsyhUserPartsstore(zsyhUserPartsstore));
    }

    /**
     * 修改配件店档案
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        ZsyhUserPartsstore zsyhUserPartsstore = zsyhUserPartsstoreService.selectZsyhUserPartsstoreById(id);
        mmap.put("zsyhUserPartsstore", zsyhUserPartsstore);
        return prefix + "/edit";
    }

    /**
     * 修改配件店档案
     */
    @GetMapping("/viewPartsStore/{id}")
    public String viewPartsStore(@PathVariable("id") String id, ModelMap mmap)
    {
        ZsyhUserPartsstore zsyhUserPartsstore = zsyhUserPartsstoreService.selectZsyhUserPartsstoreById(id);
        mmap.put("zsyhUserPartsstore", zsyhUserPartsstore);
        return prefix + "/viewPartsStore";
    }

    /**
     * 修改保存配件店档案
     */
    @RequiresPermissions("zsyh:partsStore:edit")
    @Log(title = "配件店档案", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ZsyhUserPartsstore zsyhUserPartsstore)
    {
        return toAjax(zsyhUserPartsstoreService.updateZsyhUserPartsstore(zsyhUserPartsstore));
    }

    /**
     * 删除配件店档案
     */
    @RequiresPermissions("zsyh:partsStore:remove")
    @Log(title = "配件店档案", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(zsyhUserPartsstoreService.deleteZsyhUserPartsstoreByIds(ids));
    }

    /**
     * 关闭配件鉴定权
     */
    @RequiresPermissions("zsyh:partsStore:add")
    @Log(title = "关闭配件鉴定权", businessType = BusinessType.INSERT)
    @PostMapping("/closePartsCheck")
    @ResponseBody
    public AjaxResult closePartsCheck(String id,String type)
    {
        ZsyhUserPartsstore zsyhUserPartsstore = zsyhUserPartsstoreService.selectZsyhUserPartsstoreById(id);
        if("1".equals(type)){
            zsyhUserPartsstore.setIsAppraisal("0");
        }else if("2".equals(type)){
            zsyhUserPartsstore.setIsAppraisal("1");
        }
        return toAjax(zsyhUserPartsstoreService.updateZsyhUserPartsstore(zsyhUserPartsstore));
    }
}
